package com.ruoyi.framework.config;

import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.ruoyi.framework.interceptor.ApiEncryptInterceptor;
import com.ruoyi.framework.config.DecryptedRequestBodyArgumentResolver;

/**
 * API加密配置
 * 
 * @author ruoyi
 */
@Configuration
public class ApiEncryptConfig implements WebMvcConfigurer
{
    /**
     * 注册API加密拦截器
     */
    @Bean
    public ApiEncryptInterceptor apiEncryptInterceptor()
    {
        return new ApiEncryptInterceptor();
    }
    
    /**
     * 注册解密请求参数解析器
     */
    @Bean
    public DecryptedRequestBodyArgumentResolver decryptedRequestBodyArgumentResolver()
    {
        return new DecryptedRequestBodyArgumentResolver();
    }
    
    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(apiEncryptInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login", "/captchaImage", "/register", "/system/config/configKey/**");
    }
    
    /**
     * 添加自定义参数解析器
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
    {
        resolvers.add(decryptedRequestBodyArgumentResolver());
    }
}